﻿using Riba.MVVMSL;

namespace MVVMtutorial
{
	public class Dialog2ViewModel : ViewModelBase
	{
		private int _calls;
		public RelayCommand CommandNotifyMain { get; private set; }

		private object _callBackData;
		public object CallBackData
		{
			get { return _callBackData; }
			set { SetPropertyValue(ref _callBackData, value, () => CallBackData); }
		}

		public Dialog2ViewModel()
		{
			CommandNotifyMain = new RelayCommand(OnCommandNotifyMain) { IsEnabled = true };
		}

		private void OnCommandNotifyMain(object commandParameter)
		{
			_calls++;

			var n = new Notifier.NotificationEventArgs(
				"MyTag",
				string.Format("Aufruf {0} aus Dialog2ViewModel", _calls),
				CallbackFromMainPage);

			Notifier.RaiseNotify(n);
		}

		private void CallbackFromMainPage(object data)
		{
			CallBackData = data;
		}
	}
}
